#pragma once
#include <unordered_map>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include "Singleton.hpp"

class IOControlLayer;

struct FileTreeNode {
    bool isDir{true};
    uint32_t inxde;
    std::string fileName;
    std::unordered_map<std::string, FileTreeNode*> child;
    FileTreeNode(const std::string&& val, uint32_t idx, bool isDir = true)
        : fileName(std::move(val)), inxde(idx), isDir(isDir)
    {}
    bool find(const std::string& c){
        return child.find(c) != child.end();
    }
};

class FileTree: public Singleton<FileTree> {
    friend class Singleton<FileTree>;
public:
    void insertDir(const std::string& str);
    bool insertFile(const std::string& str, const std::string &data);
    void insertInitialize(const std::string& str, uint32_t idx);
    uint32_t search(const std::string& str);
    void print(const std::string& str);

private:
    std::vector<std::string> splitPath(const std::string& path);

private:
    FileTreeNode* _rootNode;

protected:
    FileTree() :_rootNode(new FileTreeNode("/", 1)) {}
    ~FileTree(){}
};
